package com.example.weatherforecast.whtrcdn.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.weatherforecast.R
import com.example.weatherforecast.whtrcdn.entity.WeatherForecastInfo

class WeatherInfoForecastListAdapter(private val context: Context, private val data: List<WeatherForecastInfo>): RecyclerView.Adapter<WeatherInfoForecastListAdapter.IndexViewHolder>() {
    val TAG = WeatherInfoForecastListAdapter::class.java.simpleName
    class IndexViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val forecastWeekday: TextView = itemView.findViewById(R.id.tv_weather_forecast_weekday)
        val type: TextView = itemView.findViewById(R.id.tv_weather_forecast_type)
        val temperatureBoundary: TextView = itemView.findViewById(R.id.tv_weather_forecast_temperature_boundary)
        val picture: ImageView = itemView.findViewById(R.id.iv_weather_forecast_type_picture)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IndexViewHolder {
        return IndexViewHolder(LayoutInflater.from(context).inflate(R.layout.weather_forecast_list_item, parent, false))
    }

    override fun onBindViewHolder(holder: IndexViewHolder, position: Int) {
        holder.forecastWeekday.text = data[position].weekday
        holder.type.text = data[position].type
        holder.temperatureBoundary.text = data[position].temperatureBoundary
    }

    override fun getItemCount(): Int {
        Log.i(TAG, "getItemCount: " + data.size)
        return data.size
    }

}